package com.bustle.web.mbean.request;

import java.util.List;
import java.util.Vector;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import com.bustle.product.ProviderDtoManager;
import com.bustle.product.dto.provider.ProviderDto;

@ManagedBean
@RequestScoped
public class ProviderListMBean
{
  @PostConstruct
  public void postBuild()
  {
    for (ProviderDto provider : providerManager.getListProvider())
    {
      providerBeans.add(new ProviderBean(provider));
    }
  }

  public List<ProviderBean> getAll()
  {
    return providerBeans;
  }

  protected List<ProviderBean> providerBeans = new Vector<>();

  @EJB
  protected ProviderDtoManager providerManager;


  static public class ProviderBean
  {
    public ProviderBean(ProviderDto aProvider)
    {
      id = aProvider.getIdProvider();
      name = aProvider.getName();
      phoneNumber = aProvider.getPhoneNumber();
      email = aProvider.getEmail();
      description = aProvider.getDescription();
      image = aProvider.getImage();
      addressBean.setName(aProvider.getAddress().getName());
      addressBean.setPostCode(aProvider.getAddress().getPostcode());
      addressBean.setCity(aProvider.getAddress().getCity());
    }

    public String show()
    {
      return ProviderMBean.SCREEN;
    }

    public int getId()
    {
      return id;
    }

    public void setId(int anId)
    {
      id = anId;
    }

    public String getName()
    {
      return name;
    }

    public void setName(String aName)
    {
      name = aName;
    }

    public String getPhoneNumber()
    {
      return phoneNumber;
    }

    public void setPhoneNumber(String aPhoneNumber)
    {
      phoneNumber = aPhoneNumber;
    }

    public String getEmail()
    {
      return email;
    }

    public void setEmail(String anEmail)
    {
      email = anEmail;
    }

    public String getDescription()
    {
      return description;
    }

    public void setDescription(String aDescription)
    {
      description = aDescription;
    }

    public String getImage()
    {
      return image;
    }

    public void setImage(String aImage)
    {
      image = aImage;
    }

    public AddressBean getAddressBean()
    {
      return addressBean;
    }

    public void setAddressBean(AddressBean anAddressBean)
    {
      addressBean = anAddressBean;
    }

    private int id;
    private String name;
    private String phoneNumber;
    private String email;
    private String description;
    private String image;
    private AddressBean addressBean = new AddressBean();


    static public class AddressBean
    {
      public String getName()
      {
        return name;
      }

      public void setName(String aName)
      {
        name = aName;
      }

      public String getPostCode()
      {
        return postCode;
      }

      public void setPostCode(String aPostCode)
      {
        postCode = aPostCode;
      }

      public String getCity()
      {
        return city;
      }

      public void setCity(String aCity)
      {
        city = aCity;
      }

      protected String name;
      protected String postCode;
      protected String city;
    }
  }
}
